package com.clear.honghefinance.admin.controller;

import com.clear.honghefinance.biz.modules.system.resource.domain.dto.CreateSysResourceDTO;
import com.clear.honghefinance.biz.modules.system.resource.domain.dto.DeleteSysResourceDTO;
import com.clear.honghefinance.biz.modules.system.resource.domain.dto.ListSysResourceDTO;
import com.clear.honghefinance.biz.modules.system.resource.domain.dto.UpdateSysResourceDTO;
import com.clear.honghefinance.biz.modules.system.resource.domain.vo.GetSysResourceVO;
import com.clear.honghefinance.biz.modules.system.resource.domain.vo.ListSysResourceVO;
import com.clear.honghefinance.biz.modules.system.resource.service.ISysResourceService;
import com.clear.honghefinance.common.dto.entity.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

@Api(tags = "系统资源")
@RestController
@RequestMapping(value = "/sysResource")
@Slf4j
public class SysResourceController {

    @Resource
    private ISysResourceService sysResourceService;

    /**
     * 创建资源
     *
     * @param dto req
     * @return
     */
    @ApiOperation(value = "创建资源")
    @PostMapping(value = "/create")
    public ApiResponse<Boolean> create(@Validated @RequestBody CreateSysResourceDTO dto) {
        return ApiResponse.success(sysResourceService.create(dto));
    }

    /**
     * 修改资源
     *
     * @param dto req
     * @return
     */
    @ApiOperation(value = "修改资源")
    @PostMapping(value = "/update")
    public ApiResponse<Boolean> update(@Validated @RequestBody UpdateSysResourceDTO dto) {
        return ApiResponse.success(sysResourceService.update(dto));
    }

    /**
     * 删除资源
     *
     * @param dto req
     * @return
     */
    @ApiOperation(value = "删除资源")
    @PostMapping(value = "/del")
    public ApiResponse<Boolean> del(@Validated @RequestBody DeleteSysResourceDTO dto) {
        return ApiResponse.success(sysResourceService.delete(dto));
    }

    /**
     * 查看资源列表
     *
     * @param dto req
     * @return
     */
    @ApiOperation(value = "查看资源列表")
    @PostMapping(value = "/list")
    public ApiResponse<List<ListSysResourceVO>> list(@Validated @RequestBody ListSysResourceDTO dto) {
        return ApiResponse.success(sysResourceService.list(dto));
    }


    /**
     * 获取资源明细
     *
     * @param id 资源id
     * @return 资源明细
     */
    @ApiOperation(value = "查询资源明细")
    @GetMapping(value = "get")
    public ApiResponse<GetSysResourceVO> get(@Validated @NotNull(message = "资源id不能为空") @RequestParam("id") Integer id) {
        return ApiResponse.success(sysResourceService.get(id));
    }
}
